package ua.pp.bizon.yandex.api.impl;

import ua.pp.bizon.yandex.api.IJobFactory;
import ua.pp.bizon.yandex.uploader.atom.AlbumsList;

import java.io.File;
import java.util.Map;
import java.util.TreeMap;

public class JobFactory implements IJobFactory {

	/*
	 * (non-Javadoc)
	 * 
	 * @see ua.pp.bizon.yandex.api.impl.IJobFactory#StartGUI()
	 */
	@Override
	public Element StartGUI() {
		Element res = new Element();
		res.setActivity(Activity.START_GUI);
		return res;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ua.pp.bizon.yandex.api.impl.IJobFactory#relogin(java.lang.String)
	 */
	@Override
	public Element relogin(String name) {
		Element res = new Element();
		res.setActivity(Activity.RELOGIN);
		Map<String, String> map = new TreeMap<String, String>();
		map.put(Element.PROP_LOGIN, name);
		res.setProperties(map);
		return res;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ua.pp.bizon.yandex.api.impl.IJobFactory#uploadFolder(java.io.File,
	 * ua.pp.bizon.yandex.uploader.atom.AlbumsList)
	 */
	@Override
	public Element uploadFolder(File from, AlbumsList to) {
		Element res = new Element();
		res.setActivity(Activity.UPLOAD_FOLDER);
		res.setProperties(new TreeMap<String, String>());
		res.getProperties().put(Element.PROP_FROM, from.getAbsolutePath());
		if (to.getElement() == null) {
			res.getProperties().put(Element.PROP_TO, AlbumsList.ID_ROOT);
		} else {
			res.getProperties().put(Element.PROP_TO, to.getID());
		}
		return res;
	}
}
